package br.com.automed.bean;

import java.io.Serializable;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.automed.entity.Consulta;
import br.com.automed.entity.Medico;
import br.com.automed.form.ControleMedicoForm;
import br.com.automed.jpautil.JPAUtil;

@Named("controleMeidicoBean")
@SessionScoped
public class ControleMeidicoBean implements Serializable {
	
	@Inject
	private UsuarioLogadoBean usuarioBean;
	private ControleMedicoForm form;
	
	public ControleMeidicoBean() {
		form = new ControleMedicoForm();
	}
	
	public boolean getEhMedico(){
		boolean flag = false;
		if(usuarioBean.getForm().getUsuario() instanceof Medico){
			flag = true;
		}
		
		return flag;
	}
	
	@SuppressWarnings("unchecked")
	public List<Consulta> getConsultasEmAberto(){
		
		List<Consulta> list = (List<Consulta>) JPAUtil.list(Consulta.NAMED_QUERY_BUSCA_CONSULTA_POR_MEDICO, "param", usuarioBean.getForm().getUsuario().getIdUsuario());
		
		return list;
	}
	
	public boolean getVerificaConsultaMarcada(){
		boolean flag = false;
		for(Consulta consulta : getConsultasEmAberto()){
			
			Calendar dtConsulta = Calendar.getInstance(Locale.getDefault());
			dtConsulta.setTime(consulta.getDataConsulta());
			int diaConsulta = dtConsulta.get(Calendar.DAY_OF_MONTH);
			int hoje = Calendar.getInstance(Locale.getDefault()).get(Calendar.DAY_OF_MONTH);
			
			if(diaConsulta == hoje){
				flag = true;
				break;
			}
		
		}
		
		return flag;
	}
	
	public void carregarMedico(){
		
	}

	public ControleMedicoForm getForm() {
		return form;
	}

	public void setForm(ControleMedicoForm form) {
		this.form = form;
	}
	
}
